//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ruoyi.framework.web.codetable;

import com.hyjx.framework.common.CommonUtil;
import com.hyjx.framework.common.tree.TreeObject;
import com.hyjx.framework.common.tree.TreeUtil;
import com.hyjx.framework.common.util.PinyinUtil;
import com.hyjx.framework.orm.dao.IBaseDao;
import com.hyjx.framework.orm.dao.Pager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Service;

@Service
public class CodetableServiceImpl implements CodetableService {
//    @Resource
//    private IBaseDao dao;

    public CodetableServiceImpl() {
    }

    public String queryList(CodetableModel model) {
//        Pager pager = this.dao.getPager("codetable.queryList", "codetable.queryCount", model);
//        return CommonUtil.getPageJsonStr(pager);
        return null ;
    }


    public boolean add(CodetableModel model) throws SQLException {
//        this.dao.addObject("codetable.insert", model);
        CodeTableManager.reloadCodeTable(model.getCodetable());
        return true;
    }

    public CodetableModel getInfoById(CodetableModel model) {
//        model = (CodetableModel)this.dao.queryObject("codetable.getInfoById", model);
        return model;
    }

    public int edit(CodetableModel model) {
//        this.dao.updateObject("codetable.update", model);
        CodeTableManager.reloadCodeTable(model.getCodetable());
        return 1;
    }

    public int delete(CodetableModel model) {
//        this.dao.deleteObject("codetable.delete", model);
        CodeTableManager.reloadCodeTable(model.getCodetable());
        return 1;
    }

    public String queryManagerList(CodeTableManagerModel model) {
//        Pager pager = this.dao.getPager("codetable.querymanagerlist", "codetable.querymanagercount", model);
//        return CommonUtil.getPageJsonStr(pager);
        return  null ;
    }


    public String dealComboTree(String codetable, String parentcode, HttpServletResponse resp) {
        List list;
        if (parentcode != null && !parentcode.equals("")) {
            list = CodeTableManager.getSubCodeList(codetable, parentcode);
        } else {
            list = CodeTableManager.getTableList(codetable);
        }

        List<TreeObject> toList = new ArrayList();
        Iterator var7 = list.iterator();

        while(var7.hasNext()) {
            CodeBean cb = (CodeBean)var7.next();
            TreeObject to = new TreeObject();
            to.setId(cb.getCode());
            to.setParent_id(cb.getParentCode());
            to.setText(cb.getName());
            toList.add(to);
        }

        String sb = TreeUtil.getEasyuiJsonStr(toList, "0", (String)null);
        return sb;
    }

    public String deal(String codetable, String parentcode, HttpServletResponse resp, String pinyin) {
        List list;
        if (parentcode != null && !parentcode.equals("")) {
            list = CodeTableManager.getSubCodeList(codetable, parentcode);
        } else {
            list = CodeTableManager.getTableList(codetable);
        }

        StringBuffer sb = new StringBuffer();
        sb.append("[");
        int i = 1;
        if (list != null) {
            Iterator var9 = list.iterator();

            while(var9.hasNext()) {
                CodeBean bean = (CodeBean)var9.next();
                if ("1".equals(bean.getValidflag())) {
                    sb.append("{");
                    sb.append("\"code\":\"" + bean.getCode() + "\",");
                    String name = "";
                    name = bean.getName();
                    if (pinyin != null && !"".equals(pinyin)) {
                        name = name + " (" + PinyinUtil.getFirstChars(bean.getName()) + ")";
                    }

                    sb.append("\"name\":\"" + name + "\"");
                    sb.append("}");
                    if (i != list.size()) {
                        sb.append(",");
                    }

                    ++i;
                }
            }
        }

        sb.append("]");
        if (sb.toString().endsWith(",]")) {
            sb.deleteCharAt(sb.toString().length() - 2);
        }

        return sb.toString();
    }
}
